local wengua_active = fk.CreateSkill {

  name = "joy__wengua&",

  tags = {  },

}



wengua_active:addEffect("active", {
  name = "joy__wengua&",
  anim_type = "support",
  card_num = 1,
  target_num = 1,
  prompt = "#wengua&",
  can_use = function(self, player)
    return player:usedSkillTimes(wengua_active.name, Player.HistoryPhase) == 0 and not player:isKongcheng()
  end,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0
  end,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and to_select ~= player.id and Fk:currentRoom():getPlayerById(to_select):hasSkill("joy__wengua")
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local id = effect.cards[1]
    local card = Fk:getCardById(id)
    player:showCards(id)
    room:obtainCard(target, id, false, fk.ReasonGive)
    if card.type == Card.TypeTrick then
      if target.maxHp < 5 then
        room:changeMaxHp(target, 1)
      end
      if target:isWounded() then
        target.room:recover({
          who = target,
          num = 1,
          recoverBy = target,
          skillName = wengua_active.name
          })
      end
    end
    if room:getCardOwner(id) ~= target or room:getCardArea(id) ~= Card.PlayerHand then return end
    local choices = {"Cancel", "Top", "Bottom"}
    local choice = room:askForChoice(target, choices, "wengua",
      "#wengua-choice::"..player.id..":"..Fk:getCardById(id):toLogString())
    if choice == "Cancel" then return end
    local index = 1
    if choice == "Bottom" then
      index = -1
    end
    room:moveCards({
      ids = effect.cards,
      from = target.id,
      toArea = Card.DrawPile,
      moveReason = fk.ReasonJustMove,
      skillName = "wengua",
      drawPilePosition = index,
    })
    if player.dead then return end
    if choice == "Top" then
      player:drawCards(1, "wengua", "bottom")
      if not target.dead then
        target:drawCards(1, "wengua", "bottom")
      end
    else
      player:drawCards(1, "wengua")
      if not target.dead then
        target:drawCards(1, "wengua")
      end
    end
  end,
})

return wengua_active